from urllib import request
from bs4 import BeautifulSoup
import chardet

url = "https://www.biqukan.com/"

# 抓取网站数据
response = request.urlopen(url).read()
# 获取网页字符编码
charset = chardet.detect(response)

# 解析网站
html = response.decode("gbk")

# 创建BeautifulSoup对象
soup = BeautifulSoup(html, 'lxml')  # 使用lxml html解析器 需要C语言库

# print(soup.prettify())#格式化网站输出
# print(soup.title)  # 获取title标签
# print(soup.head)  # 获取head标签
# print(soup.a)  # 获取第一个a标签
# print(soup.find_all("a"))  # 获取所有的a标签
# print(soup.a.em)  # 获取第一个a标签下的em标签
# print(soup.a.em.string)  # 获取标签里的信息
for child in soup.body.ul.children:  # 子标签
    print(child)
print("-" * 20)
print(soup.body.ul.contents[1])  # 以下标获取元素信息
